package kr.saeildamil.androidstudy.ch07;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class DrawBitmap2Ex extends Activity {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		DrawView2 dv = new DrawView2(this);
		setContentView(dv);
	}
}

class DrawView2 extends View {
	Bitmap btm;
	Canvas offscreen;
	Paint ptn;
	Bitmap backbit;
	
	public DrawView2(Context context) {
		super(context);
		btm = BitmapFactory.decodeResource(getResources(), R.drawable.harubang);
		backbit = Bitmap.createBitmap(300, 200, Bitmap.Config.ARGB_8888);
		offscreen = new Canvas(backbit);
		offscreen.drawColor(Color.GREEN);
		ptn = new Paint();
		ptn.setColor(Color.RED);
	}

	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.drawColor(Color.LTGRAY);
		for(int x=0; x<300; x+=10){
			offscreen.drawLine(x, 0, 300-x, 200, ptn);
		}
		canvas.drawBitmap(backbit, 10, 10, null);	
	}
}
